const {
  get,
  post,
} = require('../../request/index')
const { typeJson } = require('../../utils/typejson');

const {getYearMateTime} = require('../../utils/time')

// pages/mainedit/mainedit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    options:{},
    op:{
      jsonType:typeJson.resultStatus
    },
    namecode:"请选择状态"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
       this.setData({
        options:{...JSON.parse(options.data)}
       })
  },
  canvasChang(e) {

      this.data.options.approvalRecordVos[0].url = e.detail
  },
  tb(){
    let {options} = this.data
   let time = new Date().getTime() 
   this.data.options.approvalRecordVos[0].approvalDate = getYearMateTime(time)
    if(this.data.options.approvalRecordVos[0].approvalResult==1 || this.data.options.approvalRecordVos[0].approvalResult==2 || this.data.options.approvalRecordVos[0].url!=''){
      post(`/app/approvalRecord/update`,{...options.approvalRecordVos[0]}).then(res=>{
        console.log(res);
        if(res.success){
          wx.showToast({
            title: '提交成功',
            icon: 'success',
            duration: 1500,
            mask: true
          })
          wx.navigateBack({
            delta: 1
          })
         }
      })
    }else{
      wx.showToast({
        title: '操作结果是必填项',
        icon: 'none',
        duration: 3000,
      })
      return false
    }
    
  },
  changeSelect(v){  
    console.log(v);
    let {options} = this.data

   
       this.setData({
         namecode:v.detail,
         options:{...options,approvalRecordVos:[{...options.approvalRecordVos[0],approvalResult:v.detail}]}
       })
      //  this.data.options.approvalRecordVos[0].approvalResult = this.data.namecode;
  },

  clivt(){
this.changeSelect()
  },
  

  changeInput(v){
    
    this.data.options.approvalRecordVos[0].approvalComment = v.detail;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})